/**
 *  Date           	Name    		     Change
 *  23/09/2014     	Roy Chan			 Creation
 *
 */
package persistence;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import persistence.model.File;

/**
 * @author Roy Chan
 *
 */
public class DaoImplTest{
	/**
	 * @param args
	 * @throws SQLException 
	 */
	public static void main(String[] args) throws Exception {
		
//		ResultSet rs;
//		SampleDBDaoImpl dao = new SampleDBDaoImpl();
//		rs = dao.selectAll();
//		convertToList(rs);
		
		FileDaoImpl fileDao = new FileDaoImpl();
		//List<FileDoc> fileList = new LinkedList<FileDoc>();
		fileDao.deleteAll();
		perparDataToDB(fileDao);
		
		//perparDataToDB(fileDao);
		
		convertToList(fileDao.selectAll());
	}
	
	
	
	public static void convertToList(ResultSet rs) {
		try {
			System.out.println("testing convertToList");
			if(!rs.next())
				System.out.println("there's no records!");
			
			while(rs.next()){
				Console(rs.getString(1)+" ");
				Console(rs.getString(2));
				Console("\n");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		
	}
	
	public static void perparDataToDB(FileDaoImpl fileDao ){
		
		for(int i=1; i<10;i++)
		{
			File file = new File();
			file.setFile_id(i);
			file.setFile_name("name"+i);
			file.setFile_size(i+10);
			file.setFile_address("address" + i);
			
			fileDao.insert(file);
		}
		System.out.println("perparDataToDB() done.");
	}



	private static void Console(String msg) {
		System.out.print(msg);
		
	}

}
